//歌单详情
let id=location.search.substr(4);
console.log(id);
fetch('http://localhost:3000/song/detail?ids='+id,{
    mode:'cors',
    method:'GET'
})
    .then(r=>r.json())
    .then(function (data) {
        console.log(data);
        $('.rollimg').setAttribute('src',data.songs[0].al.picUrl);
        //获取歌曲信息
        fetch("http://localhost:3000/song/url"+location.search,{
            method:"get",
            mode:"cors"
        })
            .then(r=>r.json())
            .then(function (data) {

                //获取歌词信息
                fetch('http://localhost:3000/lyric'+location.search,{
                    method:"get",
                    mode:"cors"
                })
                    .then(r=>r.json())
                    .then(function (data) {
                        // 未划分的歌词
                        let string=''
                        let str=data.lrc.lyric;
                        let lyric=new Lyric(data.lrc.lyric,function (obj) {
                            console.log(obj);
                            let i=obj.lineNum;
                            $('.song_iner').style['transform']=`translateY(-${32*i}px)`;
                            console.log(obj.lineNum);
                            $('.song_iner').children[i].className='active';
                        })
                        $(".song_light").onclick=function () {
                            if(flag%2==1){
                                $(".song_playbtn").style.display="none"
                                $('.a-circling.z-pasuse').style.animationPlayState='running'
                                $('#myaudio').play();
                                $('.song_iner').style.animationPlayState='running'
                                lyric.togglePlay();
                            }
                            else {
                                $(".song_playbtn").style.display="block"
                                $('.a-circling.z-pasuse').style.animationPlayState='paused'
                                $('#myaudio').pause();
                                $('.song_iner').style.animationPlayState='paused'
                                lyric.stop();
                            }
                            flag+=1;
                        }
                        let strs=new Array();
                        strs=str.split("\n")
                        for(let i=0;i<strs.length;i++){
                            string+=
                                `
                                    <p class="song_lyricitem">${strs[i].substring(11)}</p>
                                `
                        }
                       $('.song_iner').innerHTML=string;
                    })

                //流媒体加载函数
                $('#myaudio').onloadedmetadata=function(){
                    //表示歌曲加载完毕
                    /*$('#myaudio').duration 歌曲时间*/
                    /*时间改变，歌曲播放触发时间改变函数,追踪*/
                    $('#myaudio').ontimeupdate=function () {
                        /*$('#myaudio').currentTime 歌曲播放的时间进度*/
                        $('.slider').value=$('#myaudio').currentTime*100/$('#myaudio').duration;

                    }
                    //通过滑块控制歌曲进度
                    $('.slider').oninput=function () {
                        $('#myaudio').currentTime=$('.slider').value*  $('#myaudio').duration/100;
                    }
                }
                /*播放按钮*/
                $('#myaudio').setAttribute('src',data.data[0].url);
                let flag=1;

            })
    })


/*选择器*/
function  $(e) {
    return document.querySelector(e)
}